global datadir  "X\codes_AP_aid"


*** Final Data for regressions

use  "$datadir/constructed/bis_n.dta", clear
 drop if year<=1994
 drop if year==1995 & quarter<4
 
rename fin_amount actualamount
summ t, d
summ t_no, d

*egen date=group(year quarter)
egen pid=group(source)
xtset pid date

** Sample of countries with at least one program
egen p_h=max(actualamount), by(pid)
gen program_sample=(p_h>0)


foreach i of varlist t t_no{
gen log_`i'=log(`i')
gen l`i'=L.`i'
gen g_`i'=D.log_`i'
replace g_`i'=g_`i'*100
}



*****

rename g_t haven_deposit
rename g_t_no nonhaven_deposit


gen imf=(actualamount>0)
gen diff=haven_deposit-nonhaven_deposit


xtset pid date
gen log_ngdp=log(ngdp_usd_weo)
gen timingb=program
replace timingb=0 if timing==.
rename timingb imf_program

keep if program_sample==1


label var haven_deposit "Haven Flows"
label var nonhaven_deposit "Non-Haven Flows"
label var diff "Diff. Flows"
label var imf "IMF disbursement quarter"
label var imf_program "IMF Program"
label var log_ngdp "Quarterly GDP (log)"


** Baseline
eststo clear
eststo: xtreg haven_deposit imf  log_ngdp i.date, fe robust
eststo: xtreg nonhaven_deposit  imf  log_ngdp i.date, fe robust
eststo: xtreg diff imf i.date log_ngdp, fe robust


** With IMF program sample
 xtreg haven_deposit imf  log_ngdp i.date if imf_program==1, fe robust
xtreg nonhaven_deposit imf  log_ngdp i.date if imf_program==1, fe robust
eststo: xtreg diff imf i.date log_ngdp if imf_program==1, fe robust

esttab using  "$datadir/output/basline_pub.tex", replace  b(3) se scalars(N r2) star(* 0.10 ** 0.05 *** 0.01) ///
keep(imf log_ngdp) ///
order(imf log_ngdp )  label compress 



